import 'package:flutter/material.dart';
import 'fileSave.dart' as fil;
import 'request.dart' as res;

class listState extends StatefulWidget {
  String status;
  String statusBh;
  String orderId;
  String id;
  String userId;

  listState(this.status, this.statusBh, this.orderId, this.id, this.userId);

  @override
  State<StatefulWidget> createState() {
    _listStateState state = new _listStateState();
    state.status = this.status;
    state.statusBh = this.statusBh;
    state.orderId = this.orderId;
    state.id = this.id;
    state.userId = this.userId;
    return state;
  }
}

class _listStateState extends State<listState> {
  dynamic obj;
  String status;
  String statusBh;
  String orderId;
  String id;
  String userId;

// 获取订单id
  _getCounter() async {
    await res.getTaskById(this.orderId).then((value) => {
          setState(() {
            this.obj = value;
          })
//    for(int i = 0; i < value['detail'])
        });
  }

  @override
  void initState() {
    print('初始化-------------------');
    super.initState();
    this._getCounter();
  }

  @override
  Widget build(BuildContext context) {
    print('00000000000000------------');
    print(obj);
    return Scaffold(
        appBar: AppBar(
            centerTitle: true,
            // 标题居中
            title: Text(
              '订单详情',
              style: TextStyle(
                color: Color.fromRGBO(255, 213, 140, 1),
              ),
            ),
            backgroundColor: Color.fromRGBO(30, 30, 30, 1),
            leading: IconButton(
                icon: Icon(
                  Icons.format_list_bulleted,
                  color: Color.fromRGBO(255, 213, 140, 1),
                ),
                onPressed: () {
                  print('菜单！！！！！！！！！！');
                }),
            actions: <Widget>[
              IconButton(
                  icon: Icon(Icons.message,
                      color: Color.fromRGBO(255, 213, 140, 1)),
                  onPressed: () {
                    print('消息！！！！！！！！！！');
                  })
            ]),
        body: new SizedBox(
//    height: 550.0,  //设置高度
          child: new Card(
            elevation: 15.0, //设置阴影
            margin: EdgeInsets.fromLTRB(10.0, 5.0, 10.0, 5.0),
            shape: const RoundedRectangleBorder(
                borderRadius: BorderRadius.all(Radius.circular(10.0))), //设置圆角
            child: new Column(
              // card只能有一个widget，但这个widget内容可以包含其他的widget
              children: [
                new Container(
                  decoration: new BoxDecoration(
                      color: Color.fromRGBO(250, 251, 252, 1)),
                  child: new ListTile(
                    title: Row(
                      children: <Widget>[
                        new Text('#',
                            style: new TextStyle(
                                color: Color.fromRGBO(0, 0, 0, 1),
                                fontWeight: FontWeight.w100,
                                fontSize: 10)),
                        new Text(obj['orderNo'],
                            style: new TextStyle(
                                color: Color.fromRGBO(0, 0, 0, 1),
                                fontWeight: FontWeight.bold,
                                fontSize: 15)),
                        new Text('立即送达',
                            style: new TextStyle(
                                color: Color.fromRGBO(0, 0, 0, 1),
                                fontWeight: FontWeight.w100,
                                fontSize: 13))
                      ],
                    ),
                    trailing: Text(status,
                        style: TextStyle(
                            color: Color.fromRGBO(0, 0, 0, 1),
                            fontWeight: FontWeight.w100,
                            fontSize: 10)),
                  ),
                ),
                new Divider(),
                new ListTile(
                  title: Row(
                    children: <Widget>[
                      new Text(obj['consignee'],
                          style: new TextStyle(
                              color: Color.fromRGBO(0, 0, 0, 1),
                              fontWeight: FontWeight.w200,
                              fontSize: 15)),
                    ],
                  ),
                ),
                new ListTile(
                  title: Row(
                    children: <Widget>[
                      new Text(obj['address'],
                          style: new TextStyle(
                              color: Color.fromRGBO(0, 0, 0, 1),
                              fontWeight: FontWeight.w100,
                              fontSize: 10)),
                    ],
                  ),
                ),
                new ListTile(
                  title: Row(
                    children: <Widget>[
                      new Text(
                          '---------------------------------------------------------',
                          style: new TextStyle(
                              color: Color.fromRGBO(215, 215, 215, 1))),
                    ],
                  ),
                ),
                new ListTile(
                  title: Row(
                    children: <Widget>[
                      new Text('商品(' + obj['count'] + ')',
                          style: new TextStyle(
                              color: Color.fromRGBO(0, 0, 0, 1),
                              fontWeight: FontWeight.w100,
                              fontSize: 15)),
                    ],
                  ),
                ),
                new Container(
                  decoration: new BoxDecoration(
                      color: Color.fromRGBO(245, 246, 247, 1)),
                  width: 100,
                  child: new ListTile(
                    title: Row(
                      children: <Widget>[
                        new Text('备注:',
                            style: new TextStyle(
                                color: Color.fromRGBO(171, 171, 172, 1),
                                fontWeight: FontWeight.w100,
                                fontSize: 13)),
                        new Text(obj['remarks'],
                            style: new TextStyle(
                                color: Color.fromRGBO(171, 171, 172, 1),
                                fontWeight: FontWeight.bold,
                                fontSize: 13))
                      ],
                    ),
                    trailing: Text(status,
                        style: TextStyle(
                            color: Color.fromRGBO(0, 0, 0, 1),
                            fontWeight: FontWeight.w100,
                            fontSize: 10)),
                  ),
                ),
                new ListTile(
                    title: Container(
                  child: Material(
                      child: Ink(
                    decoration: BoxDecoration(
                      color: Color.fromRGBO(255, 174, 0, 1),
                      //设置四周圆角 角度
                      borderRadius: BorderRadius.all(Radius.circular(10.0)),
                      //设置四周边框
                      border: new Border.all(
                          width: 1, color: Color.fromRGBO(202, 172, 108, 1)),
                    ),
                    child: InkResponse(
                      borderRadius:
                          new BorderRadius.all(new Radius.circular(10.0)),
                      //点击或者toch控件高亮时显示的控件在控件上层,水波纹下层
                      highlightColor: Colors.yellow,
                      //点击或者toch控件高亮的shape形状
                      highlightShape: BoxShape.rectangle,
                      //.InkResponse内部的radius这个需要注意的是，我们需要半径大于控件的宽，如果radius过小，显示的水波纹就是一个很小的圆，
                      //水波纹的半径
                      radius: 300.0,
                      //水波纹的颜色
                      splashColor: Colors.yellow,
                      //true表示要剪裁水波纹响应的界面   false不剪裁  如果控件是圆角不剪裁的话水波纹是矩形
                      containedInkWell: true,
                      //点击事件
                      onTap: () {
                        if (statusBh == '0') {
                          res.addOrder(orderId, userId).then((value) => {
                                if (value['code'] == '0')
                                  {
                                    showDialog(
                                      context: context,
                                      builder: (BuildContext context) {
                                        return new AlertDialog(
                                            title: new Text(
                                              '提示',
                                              style: new TextStyle(
                                                color: Colors.black54,
                                                fontSize: 18.0,
                                              ),
                                            ),
                                            content: new Text('操作成功！'),
                                            actions: <Widget>[
                                              FlatButton(
                                                  onPressed: () {
                                                    Navigator.of(context).pop();
                                                  },
                                                  child: Text('确定'))
                                            ]);
                                      },
                                    )
                                  }
                                else
                                  {
                                    showDialog(
                                      context: context,
                                      builder: (BuildContext context) {
                                        return new AlertDialog(
                                            title: new Text(
                                              '提示',
                                              style: new TextStyle(
                                                color: Colors.black54,
                                                fontSize: 18.0,
                                              ),
                                            ),
                                            content: new Text(value['msg']),
                                            actions: <Widget>[
                                              FlatButton(
                                                  onPressed: () {
                                                    Navigator.of(context).pop();
                                                  },
                                                  child: Text('确定'))
                                            ]);
                                      },
                                    )
                                  }
                              });
                        } else {
                          res
                              .updateStatus(
                                  (int.parse(statusBh)).toString(), id, orderId)
                              .then((value) => {
                                    if (value['code'] == '0')
                                      {
                                        showDialog(
                                          context: context,
                                          builder: (BuildContext context) {
                                            return new AlertDialog(
                                                title: new Text(
                                                  '提示',
                                                  style: new TextStyle(
                                                    color: Colors.black54,
                                                    fontSize: 18.0,
                                                  ),
                                                ),
                                                content: new Text('操作成功！'),
                                                actions: <Widget>[
                                                  FlatButton(
                                                      onPressed: () {
                                                        Navigator.of(context)
                                                            .pop();
                                                      },
                                                      child: Text('确定'))
                                                ]);
                                          },
                                        )
                                      }
                                    else
                                      {
                                        showDialog(
                                          context: context,
                                          builder: (BuildContext context) {
                                            return new AlertDialog(
                                                title: new Text(
                                                  '提示',
                                                  style: new TextStyle(
                                                    color: Colors.black54,
                                                    fontSize: 18.0,
                                                  ),
                                                ),
                                                content: new Text(value['msg']),
                                                actions: <Widget>[
                                                  FlatButton(
                                                      onPressed: () {
                                                        Navigator.of(context)
                                                            .pop();
                                                      },
                                                      child: Text('确定'))
                                                ]);
                                          },
                                        )
                                      }
                                  });
                        }
                      },
                    ),
                  )),
                ))
              ],
            ),
          ),
        ));
  }
}
